%   Main paper: S. Mirjalili, A. Lewis                                    %
%               The Whale Optimization Algorithm,                         %
%               Advances in Engineering Software , in press,              %
%               DOI: http://dx.doi.org/10.1016/j.advengsoft.2016.01.008   %
%   Edited by: Quoc-Viet Pham                                             %

% This function initializes the first population of search agents
function Positions = initialization(SearchAgents_no, dim, ub, lb)

Boundary_no = size(ub,2); % numnber of boundaries

% If the boundaries of all variables are equal and user enter a single
% number for both ub and lb
if Boundary_no == 1
    Positions = rand(SearchAgents_no,dim).*(ub - lb) + lb;
end

% If each variable has a different lb and ub
if Boundary_no > 1
    for i = 1:dim
        ub_i = ub(i);
        lb_i = lb(i);
        Positions(:,i) = rand(SearchAgents_no,1).*(ub_i - lb_i) + lb_i;
    end
end